package com.example.automanagement.controller;

import com.example.automanagement.entity.*;
import com.example.automanagement.service.HomeDataService;
import com.example.automanagement.util.Result;
import com.example.automanagement.views.autoStatusNumber;
import com.example.automanagement.views.autoTypeNumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class HomeDataController {
    @Autowired
    private HomeDataService homeService;

    @GetMapping(value = "/getHomeData")
    public Result getRoleBusiness(){
        try {
            List<HomeTableData> tableData =homeService.getHomeTableData();
            return Result.success(tableData,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    // 根据用户Id获取预警列表
    @GetMapping(value = "/getAlarmList")
    public Result getAlarmList(@RequestParam("userId") String userId){
        try {
            List<Alarm> alarmList =homeService.getUserAlarm(userId);
            return Result.success(alarmList,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    // 根据用户Id获取告警列表
    @GetMapping(value = "/getWarnList")
    public Result getWarnList(@RequestParam("userId") String userId){
        try {
            List<Warning> warnList =homeService.getUserWarning(userId);
            return Result.success(warnList,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    // 根据用户Id获取待办已完成列表
    @GetMapping(value = "/getTodoDoneList")
    public Result getTodoDoneList(@RequestParam("userId") String userId){
        try {
            List<ToDo> todoList =homeService.getUserTodoDone(userId);
            return Result.success(todoList,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    // 根据用户Id获取待办未完成列表
    @GetMapping(value = "/getTodoUndoneList")
    public Result getTodoUndoneList(@RequestParam("userId") String userId){
        try {
            List<ToDo> todoList =homeService.getUserTodoUndone(userId);
            return Result.success(todoList,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    //根据ID查询用户未完成待办的数量
    @GetMapping(value = "/getTodoUndoneNumber")
    public Result getTodoUndoneNumber(@RequestParam("userId") String userId){
        try {
            int todoUndoneNumber =homeService.getTodoUndoneNumber(userId);
            return Result.success(todoUndoneNumber,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    //查询各状态车辆数目
    @GetMapping(value = "/getAutoStatusNumber")
    public Result getAutoStatusNumber(){
        try {
            List<autoStatusNumber> autoStatusNumber =homeService.getAutoStatusNumber();
            return Result.success(autoStatusNumber,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
    //查询各种类型车辆数目
    @GetMapping(value = "/getAutoTypeNumber")
    public Result getAutoTypeNumber(){
        try {
            List<autoTypeNumber> autoTypeNumber =homeService.getAutoTypeNumber();
            return Result.success(autoTypeNumber,"查询成功");
        } catch (Exception e) {
            return Result.error("500","查询失败！");
        }
    }
}
